package com.woniuxy.factory.controller;

import com.woniuxy.factory.entity.ProductIn;
import com.woniuxy.factory.entity.ResponseResult;
import com.woniuxy.factory.service.ProductInService;
import com.woniuxy.factory.util.AuditType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 邹佳骏
 * @date 2020-08-23 17:03
 */
@Controller
public class ProductInController {

    @Autowired
    ProductInService productInService;

    @ResponseBody
    @GetMapping("/pruductin")
    public ResponseResult<List<ProductIn>> selectAllProductIn(int page,int limit,ProductIn productIn){
        ResponseResult<List<ProductIn>> responseResult = new ResponseResult<>();
        System.out.println("page:"+page+"limit:"+limit);
        List<ProductIn> productIns = productInService.selectAllProductIn(page, limit, productIn);
        System.out.println("长度："+productIns.size());
        int count = productInService.selectAllCount();
        //判断是否有数据
        if(count==0){
            responseResult.setMsg("暂时无数据");
            return responseResult;
        }
        //为统一响应格式设置数据
        responseResult.setMsg("查询成功");
        responseResult.setCount(count);
        responseResult.setData(productIns);
        responseResult.setCode(AuditType.No_Approval);
        for (ProductIn in : productIns) {
            System.out.println(in.toString());
        }

        return responseResult;
    }

    @ResponseBody
    @RequestMapping("/updateproductin")
    public ResponseResult updateRealCount(ProductIn productIn,String serialNumber){

        ResponseResult responseResult = productInService.updateRealCount(productIn,serialNumber);

        return  responseResult;
    }
}
